package com.corpgovernment.organization.dataloader.db;

import com.corpgovernment.permission.entity.db.MbUserRole;
import com.corpgovernment.permission.mapper.UserRoleMapper;
import com.ctrip.corp.obt.generic.utils.CollectionUtils;
import com.ctrip.corp.obt.generic.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;

/**
 * @author jhxue
 * @create 2022-02-23-11:06
 */
@Component
public class MbUserRoleLoader {

	@Autowired
	private UserRoleMapper userRoleMapper;

	public List<MbUserRole> selectByRoleIds(List<Long> roleIds) {
		if (CollectionUtils.isEmpty(roleIds)) {
			return new ArrayList<>();
		}
		Example example = new Example(MbUserRole.class);
		example.createCriteria().andIn("roleId", roleIds);
		return userRoleMapper.selectByExample(example);
	}

	public void deleteRoleByUid(String uid) {
		if (StringUtils.isEmpty(uid)) {
			return;
		}
		Example example = new Example(MbUserRole.class);
		example.createCriteria().andEqualTo("uid", uid);
		userRoleMapper.deleteByExample(example);
	}
}
